<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>基础表单</title>
    <link rel="stylesheet" href="__LIBS__/layui/css/layui.css" />
    <link rel="stylesheet" href="__MODULE__/admin.css?v=317" />
    <link rel="stylesheet" href="__JS__/plugins/wx-audio/wx-audio.css" ><!--音频播放器组件-->
    <link rel="stylesheet" href="__JS__/plugins/webuploader/webuploader.css?v=1.0.1" ><!--webUploader上传组件-->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #formBasForm {
            max-width: 1000px;
            margin: 30px 50px;
        }

        .layui-form-item {
            display: flex ;
        }

        .layui-form-label {
            flex: 3;
        }

        .layui-input-block {
            flex: 14;
        }

        .layui-input-block {
            margin-left: 20px !important;
            min-height: 36px;
        }

        #formBasForm .layui-form-item {
            margin-bottom: 25px;
        }
    </style>
</head>

<body>
<!-- 加载动画 -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <ul class="layui-tab-title" style="margin-bottom: 20px;">
            <li><a ew-href="{:url('course')}" ew-title="直播管理">直播管理</a></li>
            <li><a ew-href="{:url('add_live')}" ew-title="添加直播">添加直播</a></li>
            <li  class="layui-this"><a href="javascript:location.reload();">添加课件</a></li>
        </ul>
        <div class="layui-card-body">
            <!-- 表单开始 -->
            <form class="layui-form" id="formBasForm" lay-filter="formBasForm">
                <input type="hidden" name="id" value="{$item['id']?$item['id']:''}">
                <input type="hidden" name="menuid" value="{$menuinfo['id']?$menuinfo['id']:''}">
                <input type="hidden" name="upload_area" value="{$upload_area?$upload_area:''}">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">选择目录:</label>
                    <div class="layui-input-block">
                        <select name="menuid" lay-verify="" lay-filter="selectmenu" lay-skin="select">
                            <option value="">请选择课程目录</option>
                            {if $menuinfo}
                            {foreach name="menus" item="vo"}
                            <option value="{$vo.id}" {$vo.id==$menuinfo['id']?'selected':''}>{$vo.menuname}</option>
                            {/foreach}
                            {else /}
                            {foreach name="menus" item="vo"}
                            <option value="{$vo.id}" >{$vo.menuname}</option>
                            {/foreach}
                            {/if}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">名称:</label>
                    <div class="layui-input-block">
                        <input name="name" class="layui-input" value="{$item['name']?$item['name']:''}" required lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">类型:</label>
                    <div class="layui-input-block">
                        <select name="type" lay-verify="" lay-filter="selectmedia" lay-skin="select">
                            <option value="0">请选择资源类型</option>
                            <option value="1">图片</option>
                            <option value="2">表格excel</option>
                            <option value="3">PDF</option>
                            <option value="4">word文档</option>
                            <option value="5">PPT</option>
                            <option value="6">MP3</option>
                            <option value="7">MP4</option>
                            <option value="8">TXT文档</option>
                            <option value="9">PSD</option>
                            <option value="10">ZIP压缩包</option>
                            <option value="11">EXE</option>
                            <option value="12">TTF字体</option>
                            <option value="13">BT种子</option>
                            <option value="14">FLASH</option>
                            <option value="15">HTML</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">上传文件：</label>
                    <input type="hidden" name="path" id="lay-file" lay-verify="music" >
                    <div class="layui-upload layui-input-block">
                        <div id="lay-upload"><i class="layui-icon">&#xe621;</i> 上传文件</div>
                    </div>
                    <p id="uploadok"></p>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">描述: </label>
                    <div class="layui-input-block">
                        <textarea name="introduce" id="LAY_editor2" >{$item['introduce']?$item['introduce']:''}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="display: flex;
                    justify-content: space-around;
                ">
                        <button id="btnDemoEdtGetContent" class="layui-btn" lay-filter="formBasSubmit" lay-submit>&emsp;提交&emsp;</button>
                        <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                    </div>
                </div>
            </form>
            <!-- //表单结束 -->
        </div>
    </div>
</div>

<!-- js部分 -->
<script type="text/javascript" src="__LIBS__/layui/layui.js"></script>
<script type="text/javascript" src="__NJS__/common.js?v=317"></script>
<script type="text/javascript" src="__LIBS__/tinymce/tinymce.min.js"></script>
<script src="__LIBS__/jquery/jquery-3.2.1.min.js"></script>
<script src="__JS__/plugins/wx-audio/wx-audio.js" ></script><!--音频播放器组件-->
<script src="__JS__/plugins/webuploader/webuploader.js"></script><!--webUploader上传组件-->
<script src="__JS__/plugins/qiniu/qiniu.min.js"></script>
<script src="__JS__/plugins/ali/aliyun-oss-sdk.min.js"></script>
<script src="__JS__/plugins/tencent/cos-js-sdk-v5.min.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js" ></script><!--百度富文本-->
<script src="__JS__/plugins/ueditor/ueditor.all.js" ></script><!--百度富文本-->
<script>
    //百度富文本编辑器
    var editor = UE.getEditor('LAY_editor2', {
        initialFrameWidth:780,
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false
    });
    //自定义上传接口
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl') {
            return '/index.php/admin/upload/ueditorUpload';//这就是自定义的上传地址
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
    var upload_area = {$upload_area} || 0;
    var isupload = false;
    var ischange = false;
    var rooturl = "{:request()->root(true)}";
    layui.use(['layer', 'form', 'laydate','jquery','cascader','upload','admin','element','tableSelect'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var cascader = layui.cascader;
        var upload = layui.upload;
        var admin = layui.admin;
        var element = layui.element

        /*音频上传*/
        var uploaderMusic = WebUploader.create({
            auto: true,// 选完文件后，是否自动上传。
            server: "{:url('admin/upload/upload')}",// 文件接收服务端。
            duplicate :true,// 重复上传文件，true为可重复false为不可重复
            pick: {
                id: "#lay-upload",// 选择文件的按钮
                multiple: true,//true多文件上传 false单文件上传
            },
            fileSingleSizeLimit: 300*1024*1024, //限制上传单个文件大小，单位是B，1M=1024000B
            accept: {
                title: 'Files',
                extensions: 'jpg,png,gif,doc,docx,xls,xlsx,ppt,pptx,pdf,mp3,mp4,txt,psd,zip,exe,ttf,bt,flash,html',
                mimeTypes: '.jpg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.mp3,.mp4,.txt,.psd,.zip,.exe,.ttf,.bt,.flash,.html'
            },
            //上传成功
            'onUploadSuccess': function(file, data, response) {
                src = data._raw
                $("#lay-file").val(src);
                $("#uploadok").html('<span style="color: red;">文件已上传成功!</span>');
            },
            //上传失败
            'uploadError':function(file){
                $('#uploadok').html('<span style="color: #FF5722;">上传失败,请检查存储配置!</span>');
            }
        });
        //资源加入队列
        uploaderMusic.on( 'fileQueued', function( file ) {
            $("#uploadok").html('<div id="' + file.id + '" style="margin: 0 10px 10px 0;display:none;"></div><p id="lay-msg">正在上传... <i class="layui-icon layui-icon-loading-1 layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></p>')
        });
        //错误信息提示
        uploaderMusic.on('error', function (code) {
            switch (code) {
                case 'F_EXCEED_SIZE':
                    layer.msg('资源大小不得超过'+  uploaderMusic.options.fileSingleSizeLimit/1024/1024 + 'MB',{icon:2,time:1500,shade:0.1});
                    break;
                case 'Q_TYPE_DENIED':
                    layer.msg('请上传正确的资源格式',{icon:2,time:1500,shade:0.1});
                    break;
                default:
                    layer.msg('上传错误，请刷新',{icon:2,time:1500,shade:0.1});
                    break;
            }
        });
        /* 监听表单提交 */
        form.on('submit(formBasSubmit)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('add_files')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    //console.log(res)
                    if (res.code == 0) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1})
                        setTimeout(function () {
                            admin.closeThisTabs();
                        }, 1000);
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });

    });
</script>
</body>

</html>